<?php
	$this->load->view('includes/head.php');
	$date = standard_date(DATE_COOKIE,$task->date_created);
	date_default_timezone_set('GMT');
?>
<div class="container">
	<div class="row">
		<div class="col-sm-12" id="update_task">
		
			<?php echo form_open('/tasks/update_task'); ?>
			<h3>You are currently editing - <small><?php echo $task->title; ?></small> <button type="submit" disabled id="edit_update" class="btn btn-info pull-right">Update</button> </h3>
			<hr>
			<div class="row">
				<div class="col-sm-8 task_description">
					<div class="form-group">
						<label for="edit_title">Title</label>
						<input type="text" class="form-control" id="edit_title" name="edit_title" value="<?php echo $task->title; ?>">
					</div>
						<input type="hidden" name="edit_id" id="edit_id" value="<?php echo $task->id; ?>" />
						<input type="hidden" name="edit_url" value="<?php echo $task->url; ?>" />
					<div class="form-group">
						<label>Description</label>
						<textarea name="edit_content" id="edit_content" class="textarea"><?php echo $task->content; ?></textarea>
					</div>
				</div>
				<div class="col-sm-4" id="info">
					
					<div class="panel panel-default">
						<div class="panel-heading"><strong>Owner:</strong> <?php echo $task->owner; ?><em class="small pull-right">Posted: <?php echo mdate('%M %d, %Y',strtotime($task->date_created)); ?></em></div>
						<div class="panel-body">

							<div class="form-group">
								<div class="row">
									<div class="col-sm-3 middle">
										<label for="date" class="nowrap">Due Date:</label>
									</div>
									<div class="col-sm-9">
										<input type="text" name="edit_date_due" id="edit_date_due" class="form-control" value="<?php echo mdate('%m/%d/%Y', strtotime($task->date_due)); ?>" />

									</div>
								</div>
							</div>

							<div class="form-group">
								<div class="row">
									<div class="col-sm-3 middle">
										<label for="priority">Priority:</label>
									</div>
									<div class="col-sm-9">
										<select class="form-control" id="edit_priority" name="edit_priority">
										  <option value="1" <?php $priority = (intval($task->priority) == 1) ? 'selected="selected"' : ""; echo $priority; ?> >Low</option>
										  <option value="2" <?php $priority = (intval($task->priority) == 2) ? 'selected="selected"' : ""; echo $priority; ?> >Normal</option>
										  <option value="3" <?php $priority = (intval($task->priority) == 3) ? 'selected="selected"' : ""; echo $priority; ?> >High</option>
										</select>
									</div>
								</div>
							</div>
					
							<div class="form-group">
								<div class="row">
									<div class="col-sm-3 middle">
										<label for="status">Status:</label>
									</div>
									<div class="col-sm-9">
										<select class="form-control" id="edit_status" name="edit_status">
										  <option value="1" <?php $status = (intval($task->status) == 1) ? 'selected="selected"' : ""; echo $status; ?> >Not Started</option>
										  <option value="2" <?php $status = (intval($task->status) == 2) ? 'selected="selected"' : ""; echo $status; ?> >In Progress</option>
										  <option value="3" <?php $status = (intval($task->status) == 3) ? 'selected="selected"' : ""; echo $status; ?> >Completed</option>
										</select>
									</div>
								</div>
							</div>
						</div>
					</div>


					<div class="panel panel-default">
						<div class="panel-heading">Assigned Role</div>
						<div class="panel-body">

							<div class="form-group">
								<p> <strong>Responsible:</strong></p>
								
								<select multiple class="form-control" id="edit_responsible" name="edit_responsible[]" >
								<?php 
									$res_array = array();
									foreach ($task->responsible as $res) {
										array_push($res_array, $res->id);
									}

									foreach ($users as $user) {
										$id = intval($user->id, 10);
										$name = $user->first_name . ' ' . $user->last_name;
										if(in_array($id, $res_array)){
											echo '<option selected value="'.$id.'">'.$name.'</option>';
										}else{
											echo '<option value="'.$id.'">'.$name.'</option>';
										}
									};
								?>
								</select>
							</div>

							<div class="form-group">
								<p><strong>Accountable: </strong></p>
								<select class="form-control" id="edit_accountable" name="edit_accountable[]">
								<?php 
									$acc_array = array();
									foreach ($task->accountable as $acc) {
										array_push($acc_array, $acc->id);
									}

									foreach ($users as $user) {
										$id = intval($user->id, 10);
										$name = $user->first_name . ' ' . $user->last_name;

										if(in_array($id, $acc_array)){
											echo '<option selected value="'.$id.'">'.$name.'</option>';
										}else{
											echo '<option value="'.$id.'">'.$name.'</option>';
										}
										
									};

								?>
								</select>
							</div>


							<div class="form-group">
								<p style="margin-bottom: 0;"><strong>Consulted: </strong></p>
								<select multiple class="form-control" id="edit_consulted" name="edit_consulted[]">
								<?php 
									$con_array = array();
									foreach ($task->consulted as $con) {
										array_push($con_array, $con->id);
									}

									foreach ($users as $user) {
										$id = intval($user->id, 10);
										$name = $user->first_name . ' ' . $user->last_name;

										if(in_array($id, $con_array)){
											echo '<option selected value="'.$id.'">'.$name.'</option>';
										}else{
											echo '<option value="'.$id.'">'.$name.'</option>';
										}
										
									};

								?>
								</select>
							</div>

							<div class="form-group">
								<p style="margin-bottom: 0;"><strong>Informed: </strong></p>
								<select multiple class="form-control" id="edit_informed" name="edit_informed[]">
								<?php 
									$informed_array = array();
									foreach ($task->informed as $inform) {
										array_push($informed_array, $inform->id);
									}
									foreach ($users as $user) {
										$id = intval($user->id, 10);
										$name = $user->first_name . ' ' . $user->last_name;

										if(in_array($id, $informed_array)){
											echo '<option selected value="'.$id.'">'.$name.'</option>';
										}else{
											echo '<option value="'.$id.'">'.$name.'</option>';
										}
										
									};

								?>
								</select>
							</div>
						</div>
					</div>


				</div>
			</div>
			<?php echo form_close(); ?>
			<hr>
		</div>
	</div>
		<div class="bottom-margin">&nbsp;</div>
		

</div>